package org.example.chapter5.service.Iml;

import org.example.chapter5.entity.Blog;
import org.example.chapter5.mapper.BlogMapper;
import org.example.chapter5.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BlogServiceIml implements BlogService {
    @Autowired
    BlogMapper blogMapper;
    @Override
    public List<Blog> findAll() {
        //通过Mapper去调用数据库的数据
        return blogMapper.selectAll();
    }


    //查询分页数据
    @Override
    public List<Blog> findByPage(Integer page, Integer size) {
        //计算第page页，需要跳过多少行
        Integer offset = (page - 1) * size;
        return blogMapper.selectBlogsByPage(offset, size);
    }
    //查询博客数量
    @Override
    public Integer count() {
        return blogMapper.selectCount();
    }
}
